package com.starnet.yarnmonitor.yarn.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starnet.yarnmonitor.yarn.vo.result.Result;
import com.starnet.yarnmonitor.yarn.entity.YarnWarnHistory;
import com.starnet.yarnmonitor.yarn.service.YarnWarnHistoryService;
import com.starnet.yarnmonitor.yarn.utils.PageUtils;
import com.starnet.yarnmonitor.yarn.vo.result.PageResult;
import com.starnet.yarnmonitor.yarn.vo.result.PageVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 陈佳豪
 * @since 2022-04-24
 */
@RestController
@RequestMapping("/yarn/warn/history")
public class YarnWarnHistoryController {
    @Autowired
    YarnWarnHistoryService yarnWarnHistoryService;

    @ApiOperation(value = "获取告警历史")
    @GetMapping
    public PageResult getPagedHistory(@RequestParam(value = "cur", required = false) Integer cur, @RequestParam(value = "size", required = false) Integer size) {
        IPage<YarnWarnHistory> historyIPage = yarnWarnHistoryService.getPagedHistory(cur, size);
        PageVO pageVo = PageUtils.getPageVOFromIPage(historyIPage);
        return PageResult.success(historyIPage.getRecords(), pageVo);
    }

    @ApiOperation(value = "恢复告警历史")
    @PutMapping
    public Result recoveryHistory(@RequestParam(value = "id") Long id) {
        yarnWarnHistoryService.recoveryHistory(id);
        return Result.success();
    }

    @ApiOperation(value = "获取未恢复的告警")
    @GetMapping("/warning")
    public PageResult getNotRecoveredWarnHistory(@RequestParam(value = "cur", required = false) Integer cur, @RequestParam(value = "size", required = false) Integer size){
        IPage<YarnWarnHistory> historyIPage =yarnWarnHistoryService.getNotRecoveredWarnHistory(cur,size);
        PageVO pageVo = PageUtils.getPageVOFromIPage(historyIPage);
        return PageResult.success(historyIPage.getRecords(), pageVo);
    }


}

